﻿using furion.blog.Domain.Shared;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Query.User
{
    public class UserListQuery : BaseQuery
    {
        public string? SearchContent { get; set; }
        public string? IsDelete { get; set; }
        public string? Status { get; set; }
        public long? RoleId { get; set; }
        public long? DeptId { get; set; }

        /// <summary>
        /// 返回查询where 和 条件参数
        /// </summary>
        /// <returns></returns>
        public (string, List<SugarParameter>) QueryParams()
        {
            List<SugarParameter> parameters = new List<SugarParameter>();
            StringBuilder strWhere = new StringBuilder(" 1=1 ");
            if (!string.IsNullOrWhiteSpace(SearchContent))
            {
                strWhere.AppendLine(" and (t.realName like @searchContent " +
                    " or t.userName like @searchContent " +
                    " or t.realName like @searchContent " +
                    " or t.phone like @searchContent " +
                    " or t.deptName like @searchContent " +
                    " ) ");
                parameters.Add(new SugarParameter("searchContent", "%"+ SearchContent + "%"));
            }
            if (!string.IsNullOrWhiteSpace(IsDelete)) {
                strWhere.AppendLine(" and t.isDelete=@isDelete ");
                parameters.Add(new SugarParameter("isDelete",IsDelete));
            }
            if (!string.IsNullOrWhiteSpace(Status)) {
                strWhere.AppendLine(" and t.status=@status ");
                parameters.Add(new SugarParameter("status", Status));
            }
            if (RoleId != null) {
                strWhere.AppendLine(" and t.roleId=@roleId ");
                parameters.Add(new SugarParameter("roleId", RoleId));
            }
            if (DeptId != null) {
                strWhere.AppendLine(" and t.deptId=@deptId ");
                parameters.Add(new SugarParameter("deptId",DeptId));
            }
           
            return (strWhere.ToString(), parameters);
        }

    }
}
